package com.situ.day9;

import org.junit.Test;

// Object、String
public class StringDemo {
    @Test
    public void test1() {
        // "java"代表字符串常量对象
        String str1 = "java";
        String str2 = new String("java");
        // ==  equals
        // ==比较的是地址值
        System.out.println(str1 == str2);//false
        // equals比较内容是不是想相等
        System.out.println(str1.equals(str2));//true
    }

    //StringBuilder、StringBuffer
    @Test
    public void test2() {
        String str1 = new String("java");
        String str2 = new String("php");
        String str3 = new String("ui");
        String str4 = new String("h5");
        String str = str1 + str2 +str3 + str4;
        System.out.println(str);
        //字符串变量拼接使用+会创建很多中间对象，不建议使用String
        //使用StringBuilder、StringBuffer,使用追加方式
        //StringBuffer:线程安全
        //StringBuilder:线程不安全
        StringBuffer buffer = new StringBuffer("java");
        buffer.append("php");
        buffer.append("ui");
        buffer.append("h5");
        System.out.println(buffer);

        StringBuilder builder = new StringBuilder("java");
        builder.append("php");
        builder.append("ui");
        builder.append("h5");
        System.out.println(builder);
    }

    @Test
    public void test3() {
        //和数学相关的工具类Math，里面的方法都是静态方法
        //'Math()' has private access in 'java.lang.Math'
        //Math math = new Math();
        int max1 = Math.max(3, 5);
        System.out.println("max1: " + max1);
        double max2 = Math.max(3.1, 5.3);
        System.out.println("max2: " + max2);

        long num1 = Math.round(3.6);//4
        double num2 = Math.ceil(3.2);//4.0
        double num3 = Math.floor(3.7);//3.0
        System.out.println("num1: " + num1);
        System.out.println("num2: " + num2);
        System.out.println("num3: " + num3);

    }
}
